package Opeartion;

import book.Book;
import book.Booklist;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class DelBook implements Operation{
    @Override
    public void work(Booklist booklist) {
        System.out.println("删除图书...");
        Scanner scanner =new Scanner(System.in);
        System.out.println("请输入删除书的名字：");
        String name=scanner.nextLine();

        int currentSize=booklist.getBrrownum();
        int pos =1;
        int i=0;
        for (i = 0; i < currentSize; i++) {
            if (booklist.getBook(i).getName().equals(name)){
                pos=i;
                break;
            }
        }
        if (i==currentSize){
            System.out.println("没有你删除的书！");
            return;
        }
        for (int j = i; j < currentSize-1; j++) {
            booklist.setBook(booklist.getBook(j+1),j);
        }
        booklist.setBook(null,currentSize-1);
        booklist.setBrrownum(currentSize-1);
        System.out.println("删除成功！");
    }
}
